﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AGR.Web.Controls.Message
{
    public partial class Message : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lnkInformationClose_Click(object sender, EventArgs e)
        {
            this.ClearMessage();
        }

        protected void lnkErrorClose_Click(object sender, EventArgs e)
        {
            this.ClearMessage();
        }

        protected void lnkWarningClose_Click(object sender, EventArgs e)
        {
            this.ClearMessage();
        }

        protected void lnkSuccessClose_Click(object sender, EventArgs e)
        {
            this.ClearMessage();
        }

        #region Public Methods

        public enum MessageType
        {
            Error,
            Success,
            Warning,
            Information
        }

        public void ShowMessage(string message, MessageType messageType)
        {
            if (messageType == MessageType.Error)
            {
                errorMessage.Visible = true;
                errorMessageLabel.Text = message.ToString();

                informationMessage.Visible = false;
                informationMessageLabel.Text = string.Empty;
                successMessage.Visible = false;
                successMessageLabel.Text = string.Empty;
                warningMessage.Visible = false;
                warningMessageLabel.Text = string.Empty;
            }
            else if (messageType == MessageType.Information)
            {
                informationMessage.Visible = true;
                informationMessageLabel.Text = message.ToString();

                successMessage.Visible = false;
                successMessageLabel.Text = string.Empty;
                warningMessage.Visible = false;
                warningMessageLabel.Text = string.Empty;
                errorMessage.Visible = false;
                errorMessageLabel.Text = string.Empty;
            }
            else if (messageType == MessageType.Success)
            {
                successMessage.Visible = true;
                successMessageLabel.Text = message.ToString();

                informationMessage.Visible = false;
                informationMessageLabel.Text = string.Empty;
                warningMessage.Visible = false;
                warningMessageLabel.Text = string.Empty;
                errorMessage.Visible = false;
                errorMessageLabel.Text = string.Empty;
            }
            else
            {
                if (messageType == MessageType.Warning)
                {
                    warningMessage.Visible = true;
                    warningMessageLabel.Text = message.ToString();

                    successMessage.Visible = false;
                    successMessageLabel.Text = string.Empty;
                    informationMessage.Visible = false;
                    informationMessageLabel.Text = string.Empty;
                    errorMessage.Visible = false;
                    errorMessageLabel.Text = string.Empty;
                }
            }
        }

        public void ClearMessage()
        {
            warningMessage.Visible = false;
            warningMessageLabel.Text = string.Empty;
            successMessage.Visible = false;
            successMessageLabel.Text = string.Empty;
            informationMessage.Visible = false;
            informationMessageLabel.Text = string.Empty;
            errorMessage.Visible = false;
            errorMessageLabel.Text = string.Empty;
        }
        #endregion
    }
}